// pages/management/closed-details/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    billId: 0,
    name: "",
    mobile: "",
    settleTime: "",
    settleAmount: 0,
    totalPackNumber: 0,
    outOrderMinTime: "",
    outOrderMaxTime: "",
    packCounts: [],
    orderPacks: []
  },

  getData() {
    wx.showLoading({
      title: "查询中..."
    });
    wx.$apis.getSettlementBillDetail(this.data.billId).then((res) => {
      let { name, mobile, settleTime, packCounts, orderPacks, totalPackNumber, outOrderMinTime, outOrderMaxTime } = res.data;
      const settleAmount = wx.$getYuan(res.data.settleAmount);
      if (res.data) {
        this.setData({
          name,
          mobile,
          settleTime: settleTime ? wx.$dayjs(settleTime).format("YYYY-MM-DD HH:mm:ss") : "",
          packCounts,
          outOrderMinTime: outOrderMinTime ? wx.$dayjs(outOrderMinTime).format("YYYY-MM-DD") : "",
          outOrderMaxTime: outOrderMaxTime ? wx.$dayjs(outOrderMaxTime).format("YYYY-MM-DD") : "",
          orderPacks: orderPacks.map((item) => {
            return {
              ...item,
              goodsOwnerUserMobile: wx.$getMobile(item.goodsOwnerUserMobile),
              outStockTime: wx.$dayjs(item.outStockTime).format("YYYY-MM-DD HH:mm:ss")
            };
          }),
          settleAmount,
          totalPackNumber
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let billId = options.id;
    this.setData({
      billId
    });
    this.getData();
  }
});
